const int analogOutPin=6;
unsigned char ledLight=0;  //LEDlight control
int flag = 1;

void setup() {
  analogWrite(analogOutPin, ledLight);  
}

void loop() {
  if(flag != 1){
    ledLight--;
    if(ledLight == 0)
      flag = (flag + 1) % 2;
     ledLight %= 256;
     analogWrite(analogOutPin, ledLight); 
  }
  else{
    ledLight++;
    if(ledLight == 256)
      flag = (flag + 1) % 2;
     ledLight %= 256;
     analogWrite(analogOutPin, ledLight); 
  }
}
